﻿using System;
using System.Collections.Generic;
using TopBuilds.Restaurant.Data;

namespace TopBuilds.Restaurant.ManagementClient
{
    public sealed class TableCollection : System.Collections.ObjectModel.ObservableCollection<Table>
    {
        private string _condition;

        public string Condition
        {
            get { return _condition; }

            set
            {
                if (_condition != null && _condition == value)
                {
                    return;
                }

                _condition = value;

                if (Count > 0)
                {
                    base.Clear();
                }

                Table[] list = TableObject.GetTables();
                if (list != null)
                {
                    foreach (Table table in list)
                    {
                        Add(table);
                    }
                }
            }
        }

        /// <summary>
        /// 初始化数据, 读入全部数据记录
        /// </summary>
        public TableCollection()
        {
            Condition = null;
        }


        public Table GetTable(int tableId)
        {
            foreach(Table table in this)
            {
                if (table.Id == tableId)
                {
                    return table;
                }
            }

            return null;
        }
    }
}
